home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / clients / Hopalong.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  3.7 KB  |  174 lines

  1. ;/*
  2. sc RESOPT IGNORE=73 DATA=NEAR MATH=FFP NMINC UCHAR CONSTLIB STREQ STRMERGE NOSTKCHK NOSTDIO OPTIMIZE OPTSIZE Hopalong.c
  3. Slink from LIB:catch.o Hopalong.o to //Clients/Hopalong LIB LIB:scmffp.lib LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Hopalong.o
  5. quit
  6.  
  7.  Hopalong 1.0  (Client for BServer)
  8.  
  9.  Copyright © 1995 by
  10.  Stefano Reksten and Luca Viola of 3AM - The Three Amigos!!!
  11.  All rights reserved.
  12.  
  13. */
  14.  
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <graphics/gfxbase.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/graphics.h>
  22. #include <proto/layers.h>
  23. #include <clib/alib_protos.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include <math.h>
  28.  
  29. #include "/include/client.h"
  30.  
  31. char *ver = "$VER: Hopalong 1.0 "__AMIGADATE__;
  32.  
  33. struct IntuitionBase *IntuitionBase;
  34. struct GfxBase *GfxBase;
  35. struct Library *LayersBase;
  36.  
  37. struct DisplayIDInformation *dinfo;
  38.  
  39. struct Screen *scr;
  40.  
  41. #define SCRDEPTH    5
  42. #define NUMCOLORS    32
  43.  
  44. UBYTE scrdepth = 5, numcolors = 32;
  45.  
  46. extern ULONG RangeSeed;
  47. UWORD swidth, sheight, maxw, maxh;
  48. UBYTE brightness;
  49.  
  50. UBYTE colors[96] =
  51. {
  52.     0,0,0, 0,5,0, 0,8,0, 0,10,0, 0,13,0, 2,13,4, 3,15,7, 5,15,10,
  53.     7,15,13, 9,15,15, 0,15,15, 0,10,14, 0,6,12, 0,3,11, 0,0,15, 4,0,14,
  54.     6,0,12, 9,0,11, 11,0,10, 12,0,7, 13,0,3, 13,1,0, 13,5,0, 13,10,0,
  55.     15,15,0, 14,14,3, 13,13,5, 12,12,7, 11,11,9, 10,10,10, 6,6,7, 4,4,4
  56. };
  57.  
  58. #define MAXITER     50000
  59. #define SCALE        50
  60. #define CHANGES        5
  61. #define XIN            0
  62. #define YIN         0
  63.  
  64.  
  65. double sgn( double x )
  66. {
  67.     return ((x>=0.0)?(1.0):(-1.0));
  68. }
  69.  
  70. void Blank( void )
  71. {
  72. ULONG displayID;
  73. struct Rectangle *rect;
  74.  
  75. register int i,px,py;
  76. double sqrt(),log(),sin();
  77. double (*ptfun[3]) ( double );
  78.  
  79. double a,b,c,x,y,x_1,y_1;
  80. long scale,changes,func;
  81.  
  82. ptfun[0]=sqrt;
  83. ptfun[1]=log;
  84. ptfun[2]=sin;
  85.  
  86. rect = GETTXTOSCANRECT(dinfo);
  87.  
  88. swidth = RECTANGLEWIDTH(rect);
  89. sheight = RECTANGLEHEIGHT(rect);
  90. displayID = DISPLAYID(dinfo);
  91. brightness = GETBRIGHTNESS(dinfo);
  92.  
  93. if ( !CheckAA() )
  94.     {
  95.     if ( displayID & SUPERHIRES )
  96.         {
  97.         displayID &= ~SUPERHIRES;
  98.         displayID |= HIRES;
  99.         }
  100.     scrdepth = 4;
  101.     numcolors = 16;
  102.     }
  103.  
  104. if ( (scr = OpenScreenTags( NULL,
  105.         SA_Width, swidth,
  106.         SA_Height, sheight,
  107.         SA_Depth, scrdepth,
  108.         SA_Type, CUSTOMSCREEN,
  109.         SA_Quiet, TRUE,
  110.         SA_DisplayID, displayID,
  111.         SA_Overscan, OSCAN_TEXT,
  112.         TAG_END ) ) )
  113.     {
  114.     SpritesOff();
  115.     for ( i = 0; i < numcolors; i+=3 )
  116.         SetRGB4( &scr->ViewPort, i, colors[i]*brightness/100, colors[i+1]*brightness/100, colors[i+2]*brightness/100 );
  117.  
  118.     while( STILL_BLANKING )
  119.         {
  120.         x=XIN; y=YIN;
  121.         SetRast( &scr->RastPort,0 );
  122.         func = RangeRand( 3 );
  123.         scale = RangeRand( 30 ) + 40;
  124.         changes = RangeRand( 5 ) + 5;
  125.         a = drand48()*2-1;
  126.         b = drand48()*2-1;
  127.         c = drand48()*2-1;
  128.  
  129.         for( i=0; i<=MAXITER; i++ )
  130.             {
  131.             x_1=y-sgn( x )*(ptfun[func])( abs( b*x-c ) );
  132.             y_1=a-x;
  133.             px=(int)((x_1*swidth)/scale)+(swidth>>1);
  134.             py=(sheight>>1)-(int)((y_1*sheight)/scale);
  135.             SetAPen( &scr->RastPort,1+(int)(numcolors*changes*i/MAXITER) );
  136.             if ( px >= 0 && px < swidth && py >= 0 && py < sheight )
  137.                 WritePixel( &scr->RastPort,px,py );
  138.             x=x_1; y=y_1;
  139.             if ( !STILL_BLANKING )
  140.                 goto exit;
  141.             }
  142.         }
  143. exit:
  144.     SpritesOn();
  145.     CloseScreen( scr );
  146.     }
  147. else
  148.     SendClientMsg( ACTION_FAILED );
  149. }
  150.  
  151.  
  152. void __main( char *line )
  153. {
  154. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  155.     {
  156.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  157.         {
  158.         if ( LayersBase = OpenLibrary( "layers.library", 37L ) )
  159.             {
  160.             if ( dinfo = OpenCommunication() )
  161.                 {
  162.                 RangeSeed = time( NULL );
  163.                 srand48( time( NULL ) );
  164.                 Blank();
  165.                 CloseCommunication( dinfo );
  166.                 }
  167.             CloseLibrary( LayersBase );
  168.             }
  169.         CloseLibrary( (struct Library *)GfxBase );
  170.         }
  171.     CloseLibrary( (struct Library *)IntuitionBase );
  172.     }
  173. }
  174.